const fs = require("fs");
const data = "这是一个stream写入流测试";

//创建写入流
const writeStream = fs.createWriteStream("output.txt");
//设置编码并写入数据
writeStream.write(data, "UTF8");
//标记文件末尾
writeStream.end();
//写入流处理
writeStream.on("finish", function () {
  console.log("写入完成");
});
writeStream.on("error", function (err) {
  console.log(err);
});

console.log("程序完成");